<template>
  <rt-list
    ref="moresearchList"
    :table-name="tableName"
    :columns="columns"
    :operations="operations"
    :custom-operations="customOperations"
    :title="title"
    :input-search-param="quickSearch"
    :controller-name="controllerName"
    :customize-action="customizeAction"
    :custom-button-operation="customButtonOperations"
    :title-list="menuList"
    :hide-title="true"
    search-placeholder="根据文章标题进行搜索"
  />
</template>

<script>
import RtList from '../../components/custome/rtList.vue';
export default {
  name: 'ArticleList',
  components: {
    RtList
  },
  data() {
    return {
      queryValue: '',
      menuList: {
        key: 'bbs_article_status',
        selected: 0,
        value: [
          {
            name: '已发布文章',
            value: '2'
          },
          {
            name: '未发布文章',
            value: '1'
          },
          {
            name: '所有的文章',
            value: '-1'
          }
        ]
      },
      controllerName: 'bbs/article',
      tableName: 'bbs_article',
      title: '自定义查询列表',
      operations: ['delete', 'search', 'publish', 'cancel', 'new'],
      columns: [
        {
          prop: 'name',
          label: '文章标题',
          sortable: true,
          type: 'customizeAction',
          actionId: 'bbs_articleid',
          autoCol: true
        },
        {
          prop: 'bbs_article_typeidname',
          label: '文章分类',
          sortable: true
        },
        {
          prop: 'releasedon',
          sortable: true,
          label: '发布时间',
          format: 'YYYY-MM-DD HH:mm:ss'
        },
        {
          prop: 'is_recommend',
          label: '是否推荐',
          sortable: true,
          map: row => `${row.is_recommend ? '是' : '否'}`
        },
        {
          prop: 'bbs_article_statusname',
          label: '状态',
          sortable: true
        }
      ],
      tableParam: {
        name: ''
      },
      quickSearch: ['name'],
      customOperations: [
        { operate: 'publish', operateName: '发布', iconName: 'rt-portal-able' },
        {
          operate: 'cancel',
          operateName: '取消发布',
          iconName: 'rt-base-disable'
        }
      ],
      customButtonOperations: {
        publish: ids => {
          if (ids.length === 0) {
            rt.showErrorToast('请至少选择一条记录');
          } else {
            this.$confirm(
              `您一共选择了${ids.length}条记录，确认要发布吗？`,
              '提示',
              {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }
            )
              .then(() => {
                let type = '2';
                rt.post(`api/bbs/article/multipublishcancel/${type}`, ids)
                  .then(res => {
                    rt.showSuccessToast('发布成功');
                    this.$refs.moresearchList.refreshTable();
                  })
                  .catch(error => {
                    rt.showErrorToast(error);
                  });
              })
              .catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消发布'
                });
              });
          }
        },
        cancel: ids => {
          if (ids.length === 0) {
            rt.showErrorToast('请至少选择一条记录');
          } else {
            this.$confirm(
              `您一共选择了${ids.length}条记录，确认要取消发布吗？`,
              '提示',
              {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }
            )
              .then(() => {
                let type = '1';
                rt.post(`api/bbs/article/multipublishcancel/${type}`, ids)
                  .then(res => {
                    rt.showSuccessToast('取消发布成功');
                    this.$refs.moresearchList.refreshTable();
                  })
                  .catch(error => {
                    rt.showErrorToast(error);
                  });
              })
              .catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消'
                });
              });
          }
        }
      }
    };
  },
  created() {},
  methods: {
    customizeAction(row, actionId) {
      this.$router.push({
        name: 'bbsarticledetail',
        query: { addAndUpdate: false, id: row[actionId] }
      });
    }
  }
};
</script>

<style scoped></style>
